package com.ruoyi.result.publication.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.result.publication.domain.ResultPublication;
import com.ruoyi.result.publication.domain.dto.ResultPublicationDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 著作信息Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-14
 */
@Mapper
public interface ResultPublicationMapper
{
    /**
     * 查询著作信息
     *
     * @param id 著作信息主键
     * @return 著作信息
     */
    public ResultPublication selectResultPublicationById(Long id);

    /**
     * 查询著作信息列表
     *
     * @param resultPublication 著作信息
     * @return 著作信息集合
     */
    public List<ResultPublication> selectResultPublicationList(ResultPublicationDTO resultPublication);

    /**
     * 新增著作信息
     *
     * @param resultPublication 著作信息
     * @return 结果
     */
    public int insertResultPublication(ResultPublication resultPublication);

    /**
     * 修改著作信息
     *
     * @param resultPublication 著作信息
     * @return 结果
     */
    public int updateResultPublication(ResultPublication resultPublication);

    /**
     * 删除著作信息
     *
     * @param id 著作信息主键
     * @return 结果
     */
    public int deleteResultPublicationById(Long id);

    /**
     * 批量删除著作信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultPublicationByIds(Long[] ids);

    List<ResultPublication> selectResultPublicationByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_publication WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(publish_date) as year, COUNT(*) as count FROM result_publication " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(publish_date) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(publish_date) as year, COUNT(*) as count FROM result_publication " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(publish_date) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);
}
